package com.nuist.springioc.controller;

import com.nuist.springioc.model.DbType;
import com.nuist.springioc.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("yml")
public class ReadymlController {

    @Value("${mykey}")
    private String key;

    @Value("${mykey.key1}")
    private String key2;

    @Value("${server.port}")
    private String port;

    @Value("${string.str1}")
    private String str1;
    @Value("${string.str2}")
    private String str2;
    @Value("${string.str3}")
    private String str3;

    @Autowired
    private Student student;  // 这里是注入了

    @Autowired
    private DbType dbType;

    @RequestMapping("/readyml")
    public String readyml() {
        return "从yml中获取文件 key:" + key;
    }

    @RequestMapping("/readyml2")
    public String readyml2() {
        return "从yml中获取 key1:" + key2;
    }

    @RequestMapping("/readyml3")
    public String readyml3() {
        return "从yml中获取 port:" + port;
    }

    @RequestMapping("/readyml4")
    public String readyml4() {
        return "从yml中获取 student 对象: " + student;
    }

    @RequestMapping("/readyml5")
    public String readYml5() {
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
        return "从yml中获取配置文件.";
    }

    @RequestMapping("/readyml6")
    public String readyml6() {
        return "从yml中获取配置文件:" + dbType + ",size:" + dbType.getName().size();
    }
}
